/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__do_print.c                                      */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/04 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <protobuf-c/protobuf-c.h>

#include "frcomm.h"
#include "frmem.h"
#include "frame.h"
#include "client.pb-c.h"
#include "frsutl.h"
#include "frcmd_server.h"
#include "apmtest_cunit.h"

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

int __do_print(Command *p_command, char **pp_result);

void case1(void)
{
    int i_ret = 0;
    Command *p_st_cmd = NULL;
    PrintCommand *print_cmd = NULL;
    char *p_args = NULL;
    char *p_result = NULL;

    //设置p_args
/*    i_size_tmp = strlen("system") + 1;
    p_args = frmalloc(i_size_tmp);
    snprintf(p_args,i_size_tmp,"%s","system");
*/
    //设置print_cmd
    print_cmd = frmalloc(sizeof(PrintCommand));
    print_command__init(print_cmd);
    print_cmd->n_args = 0;
    print_cmd->args = &p_args;
    print_cmd->cmd = NULL;

    //设置p_st_cmd
    p_st_cmd = frmalloc(sizeof(Command));
    command__init(p_st_cmd);
    p_st_cmd->print_cmd = print_cmd;
    p_st_cmd->cmd_type = 5;

    i_ret = __do_print(p_st_cmd,&p_result);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    frfree(print_cmd->cmd);
    frfree(print_cmd);
    frfree(p_st_cmd);

}

void case2(void)
{
    int i_ret = 0;
    Command *p_st_cmd = NULL;
    PrintCommand *print_cmd = NULL;
    char *p_args = NULL;
    int i_size_tmp = 0;
    char *p_result = NULL;

    //设置p_args
/*    i_size_tmp = strlen("system") + 1;
    p_args = frmalloc(i_size_tmp);
    snprintf(p_args,i_size_tmp,"%s","system");
*/
    //设置print_cmd
    print_cmd = frmalloc(sizeof(PrintCommand));
    print_command__init(print_cmd);
    print_cmd->n_args = 0;
    print_cmd->args = &p_args;
    i_size_tmp = strlen("ct") + 1;
    print_cmd->cmd = frmalloc(i_size_tmp);
    snprintf(print_cmd->cmd,i_size_tmp,"%s","ct");

    //设置p_st_cmd
    p_st_cmd = frmalloc(sizeof(Command));
    command__init(p_st_cmd);
    p_st_cmd->print_cmd = print_cmd;
    p_st_cmd->cmd_type = 5;

    i_ret = __do_print(p_st_cmd,&p_result);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);

    frfree(print_cmd->cmd);
    frfree(print_cmd);
    frfree(p_st_cmd);

}

void case3(void)
{
    int i_ret = 0;
    Command *p_st_cmd = NULL;
    PrintCommand *print_cmd = NULL;
    char *p_args = NULL;
    int i_size_tmp = 0;
    char *p_result = NULL;

    //设置p_args
/*    i_size_tmp = strlen("system") + 1;
    p_args = frmalloc(i_size_tmp);
    snprintf(p_args,i_size_tmp,"%s","system");
*/
    //设置print_cmd
    print_cmd = frmalloc(sizeof(PrintCommand));
    print_command__init(print_cmd);
    print_cmd->n_args = 0;
    print_cmd->args = &p_args;
    i_size_tmp = strlen("filter") + 1;
    print_cmd->cmd = frmalloc(i_size_tmp);
    snprintf(print_cmd->cmd,i_size_tmp,"%s","filter");

    //设置p_st_cmd
    p_st_cmd = frmalloc(sizeof(Command));
    command__init(p_st_cmd);
    p_st_cmd->print_cmd = print_cmd;
    p_st_cmd->cmd_type = 5;

    i_ret = __do_print(p_st_cmd,&p_result);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);

    frfree(print_cmd->cmd);
    frfree(print_cmd);
    frfree(p_st_cmd);

}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__do_print 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);

    CU_add_test(pSuite, "case2", case2);

    CU_add_test(pSuite, "case3", case3);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();

    return 0;
}
